package com.ctgu.蓝桥杯真题.B组2018;

import java.io.*;
import java.util.*;

/**
 * @author: Backdiy
 * @data: 2021/4/12 19:39
 * @desc:
 */
public class F递增三元组 {
    public static void main(String[] args) throws IOException {
        StreamTokenizer streamTokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        streamTokenizer.nextToken();
        long n = (long) streamTokenizer.nval;
        Map<Pair, Pair> pairs = new TreeMap<>();
        long type = 1;
        for (long i = 0; i < 3 * n; i++) {
            if (i >= n && i < 2 * n) {
                type = 2;
            } else if (i >= 2 * n) {
                type = 3;
            }

            streamTokenizer.nextToken();
            long nval = (long) streamTokenizer.nval;

            Pair pair = new Pair(nval, type);
            if (pairs.containsKey(pair)) {
                pairs.put(pair, new Pair(pairs.get(pair).ind + 1, 0));
            } else {
                pairs.put(pair, new Pair(1, 0));
            }
        }
        long x1 = 0, x2 = 0, x22 = 0, x3 = 0;
        for (Pair pair :
                pairs.keySet()) {
            long a = pair.ind;
            long b = pair.type;
            long c = pairs.get(pair).ind;
            if (b == 1) {
                x1 += c;
            } else if (b == 2) {
                Pair now = new Pair(a, 1);
                long d = (long) x2;
                if (pairs.containsKey(now)) {
                    Pair data = pairs.get(now);
                    //出去type2与type1相同的部分
                    x2 += (x1 - data.ind) * c;
                } else {
                    x2 += x1 * c;
                }
                pairs.put(pair, new Pair(c, d));
            }
            if (b == 3) {
                Pair now = new Pair(a, 2);
                //出去type3与type2相同的部分
                if (pairs.containsKey(now)) {
                    Pair data = pairs.get(now);
                    x3 += data.type * c;
                } else {
                    x3 += x2 * c;
                }
            }
        }
        PrintWriter prlongWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        prlongWriter.println(x3);
        prlongWriter.flush();
    }
}

class Pair implements Comparable<Pair> {
    long ind;
    long type;

    public Pair(long ind, long type) {
        this.ind = ind;
        this.type = type;
    }

    @Override
    public String toString() {
        return ind + "\t" + type;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Pair pair = (Pair) o;
        return ind == pair.ind && type == pair.type;
    }

    @Override
    public int hashCode() {
        return Objects.hash(ind, type);
    }

    @Override
    public int compareTo(Pair o) {
        if (this.ind == o.ind) {
            return (int) (this.type - o.type);
        } else {
            return (int) (this.ind - o.ind);
        }
    }
}
